﻿#if NETSTANDARD2_0 || NETCOREAPP3_0
using Longbow.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Specialized;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 数据库日志配置服务注入方法扩展类
    /// </summary>
    public static class DBLoggerFactoryExtensions
    {
        /// <summary>
        /// 添加文件日志功能到服务容器中
        /// </summary>
        /// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
        /// <param name="action">日志操作类回调方法，使用者在此回调中将异常记录到数据库中</param>
        public static ILoggingBuilder AddDBLogger(this ILoggingBuilder builder, Action<Exception, NameValueCollection> action)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));
            builder.Services.AddSingleton<ILoggerProvider>(new DBLoggerProvider(builder.Services, action));
            return builder;
        }
    }
}
#endif
